package com.jacob.cloud.mall.common.common;

import com.google.common.collect.Sets;
import com.jacob.cloud.mall.common.exception.MallException;
import com.jacob.cloud.mall.common.exception.MallExceptionEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 系统常量值
 */
@Component
public class Constant {

    // 登录用户session属性名
    public static final String MALL_USER = "mall_user";

    // MD5盐值
    public static final String SALT = "; faohfpkajg";

    /**
     * 商品排序
     */
    public interface ProductListOrderBy {
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price desc", "price asc");
    }

    /**
     * 商品状态
     */
    public interface ProductStatus {
        /** 0代表商品下架 */
        Integer NOT_SELL = 0;
        /** 1代表商品上架 */
        Integer SELL = 1;
    }

    /**
     * 购物车是否已勾选
     */
    public interface CartSelected{
        /** 0代表未勾选 */
        Integer NOT_SELECTED = 0;
        /** 1代表已勾选 */
        Integer SELECTED = 1;
    }

    public enum OrderStatusEnum {
        /**
         * 取消订单
         */
        CANCEL_ORDER(0, "取消订单"),
        /**
         * 已下单未付款
         */
        NOT_PAID(10, "已下单未付款"),
        /**
         *已付款
         */
        PAID(20, "已付款"),
        /**
         *已发货
         */
        DEVELIVERED(30, "已发货"),
        /**
         *已签收
         */
        FINASHED(40, "已签收");

        private String value;
        private int code;

        public static OrderStatusEnum codeOf(int code) {
            for (OrderStatusEnum orderStatusEnum : values()) {
                if (orderStatusEnum.getCode() == code) {
                    return orderStatusEnum;
                }
            }
            throw new MallException(MallExceptionEnum.NO_ENUM);
        }

        OrderStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }
    }
}
